package com.ruoyi.web.controller.moon;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.moon.domain.MoonNoticeTemplate;
import com.ruoyi.moon.service.IMoonNoticeTemplateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息模版Controller
 * 
 * @author admin
 * @date 2024-11-08
 */
@RestController
@RequestMapping("/moon/template")
public class MoonNoticeTemplateController extends BaseController
{
    @Autowired
    private IMoonNoticeTemplateService moonNoticeTemplateService;

    /**
     * 查询消息模版列表
     */
    @PreAuthorize("@ss.hasPermi('moon:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(MoonNoticeTemplate moonNoticeTemplate)
    {
        startPage();
        List<MoonNoticeTemplate> list = moonNoticeTemplateService.selectMoonNoticeTemplateList(moonNoticeTemplate);
        return getDataTable(list);
    }

    /**
     * 导出消息模版列表
     */
    @PreAuthorize("@ss.hasPermi('moon:template:export')")
    @Log(title = "消息模版", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MoonNoticeTemplate moonNoticeTemplate)
    {
        List<MoonNoticeTemplate> list = moonNoticeTemplateService.selectMoonNoticeTemplateList(moonNoticeTemplate);
        ExcelUtil<MoonNoticeTemplate> util = new ExcelUtil<MoonNoticeTemplate>(MoonNoticeTemplate.class);
        util.exportExcel(response, list, "消息模版数据");
    }

    /**
     * 获取消息模版详细信息
     */
    @PreAuthorize("@ss.hasPermi('moon:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(moonNoticeTemplateService.selectMoonNoticeTemplateById(id));
    }

    /**
     * 新增消息模版
     */
    @PreAuthorize("@ss.hasPermi('moon:template:add')")
    @Log(title = "消息模版", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MoonNoticeTemplate moonNoticeTemplate)
    {
        return toAjax(moonNoticeTemplateService.insertMoonNoticeTemplate(moonNoticeTemplate));
    }

    /**
     * 修改消息模版
     */
    @PreAuthorize("@ss.hasPermi('moon:template:edit')")
    @Log(title = "消息模版", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MoonNoticeTemplate moonNoticeTemplate)
    {
        return toAjax(moonNoticeTemplateService.updateMoonNoticeTemplate(moonNoticeTemplate));
    }

    /**
     * 删除消息模版
     */
    @PreAuthorize("@ss.hasPermi('moon:template:remove')")
    @Log(title = "消息模版", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(moonNoticeTemplateService.deleteMoonNoticeTemplateByIds(ids));
    }
}
